﻿<%@ Page Language="C#" AutoEventWireup="true" CodeFile="LeaveMessage.aspx.cs" Inherits="admin_LeaveMessage"
    MasterPageFile="~/admin/AdminMasterPage.master" %>

<%@ Register Assembly="AspNetPager" Namespace="Wuqi.Webdiyer" TagPrefix="webdiyer" %>
<asp:Content ID="head" ContentPlaceHolderID="head" runat="server">
    <style type="text/css">
        .state
        {
            cursor: pointer;
        }
        .buy
        {
            cursor: pointer;
        }
    </style>
</asp:Content>
<asp:Content ID="main" ContentPlaceHolderID="main" runat="server">
    <div class="panel panel-default">
        <div class="panel-body">
            <blockquote>
                <p style="font-family: 'Microsoft YaHei'">
                    文章管理</p>
            </blockquote>
            <table class="table table-hover" style="margin: 0 auto;">
                <thead>
                    <tr>
                        <th>
                            #
                        </th>
                        <th>
                            昵称
                        </th>
                        <th>
                            内容
                        </th>
                        <th>
                            手机号
                        </th>
                        <th>
                            访客地址
                        </th>
                        <th>
                            留言时间
                        </th>
                        <th>
                            回复状态
                        </th>
                    </tr>
                </thead>
                <tbody>
                    <asp:Repeater ID="Repeater1" runat="server" OnItemDataBound="Repeater1_ItemDataBound">
                        <ItemTemplate>
                            <tr class="listtable">
                                <td>
                                    <%#Eval("ID") %>
                                </td>
                                <td>
                                    <%#Eval("NikeName")%>
                                </td>
                                <td>
                                    <asp:Literal ID="text_Content" runat="server" Text='<%#Eval("Content")%>'></asp:Literal>
                                </td>
                                <td>
                                    <%#Eval("PhoneNum")%>
                                </td>
                                <td>
                                    <%#Eval("IPforAddress")%>
                                </td>
                                <td>
                                    <%#Eval("MTime")%>
                                </td>
                                <td class="state" data-toggle="modal" data-target="#myModal">
                                    <a>
                                        <asp:Literal ID="text_State" runat="server" Text='<%#Eval("ReplyState")%>'></asp:Literal></a>
                                </td>
                                <td class="buy">
                                    <a>删除</a>
                                </td>
                            </tr>
                        </ItemTemplate>
                        <FooterTemplate>
                            <asp:Literal ID="Literal1" runat="server" Text="当前没有任何数据！" Visible='<%#bool.Parse((Repeater1.Items.Count==0).ToString())%>'></asp:Literal>
                        </FooterTemplate>
                    </asp:Repeater>
                </tbody>
            </table>
            <div style="margin: 10px auto;">
                <webdiyer:AspNetPager ID="AspNetPager1" runat="server" FirstPageText="首页" LastPageText="尾页"
                    NextPageText="下一页" PrevPageText="上一页" ShowCustomInfoSection="Left" ShowInputBox="Never"
                    OnPageChanged="AspNetPager1_PageChanged" UrlPaging="True" PageSize="10">
                </webdiyer:AspNetPager>
            </div>
            <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"
                aria-hidden="true">
                <div class="modal-dialog">
                    <div class="modal-content">
                        <div class="modal-header">
                            <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                                <span aria-hidden="true">&times;</span></button>
                            <h4 class="modal-title" id="myModalLabel" style=" font-family:Microsoft YaHei UI">
                               回复内容</h4>
                        </div>
                        <div class="modal-body">
                       <div id="tc_main"></div>
                       <hr />
                       <textarea id="tc_text" class="form-control"  rows="3" placeholder="输入需要回复内容"></textarea>
                           <div id="SendMessage" style="margin:0px auto; text-align:center;padding:5px;"></div>
                        </div>
                        <div class="modal-footer">
                            <button type="button" class="btn btn-default" data-dismiss="modal">
                                关闭</button>
                            <button type="button" id="btn_go" class="btn btn-primary">
                                保存</button>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</asp:Content>
<asp:Content ID="JS" ContentPlaceHolderID="footJS" runat="server">
    <script type="text/javascript">
        $(document).ready(function () {
            $(".navbar-collapse").find("li").eq(4).addClass("active").siblings().removeClass("active");
            var CommodityID = 0;
            var num = 0;
        var text_reply=null;
            $(".listtable").find("td:eq(7)").click(function () {
                CommodityID = $(this).parent().find("td:eq(0)").text();
                DeleteMessage(CommodityID);
            });
            $(".listtable").find("td:eq(6)").click(function () {
                num = $(this).parent().find("td:eq(0)").text();
                ReplyMessage(num);
            });
            $("#btn_go").click(function () {
                text_reply = $("#tc_text").val();
                relyer(num,text_reply); 
            });
        });
        function ReplyMessage(ID) {
            $.ajax({
                type: "POST",
                url: "AJAX/ReplyMessage.ashx",
                data: { 'ID': ID },
                datatype: "text/json",
                beforeSend: function () {
                    $('#tc_main').append('<img alt="loading"/>').children().attr({ src: '../img/Common/loading.gif' });
                },
                success: function (msg) {
                    getjson(msg);
                }
            });
        }
        function getjson(msg) {
            var obj = JSON.parse(msg);
            $("#tc_main").empty().append(obj.Content);
            $("#tc_text").empty().val(obj.Reply);
            if (obj.Reply != "") {
                $("#tc_text").attr("disabled", true);
                $("#btn_go").attr("disabled", true);
            }
            else {
                $("#tc_text").attr("disabled", false);
                $("#btn_go").attr("disabled", false);
            }
        }
        function DeleteMessage(ID) {
            $.ajax({
                type: "POST",
                url: "AJAX/DeleteMessage.ashx",
                data: { 'ID': ID },
                datatype: "text/json",
                success: function (msg) {
                    alert("成功删除评论！");
                    location.reload();
                }
            });
        }
        function relyer(ID, text_reply) {
            $.ajax({
                type: "POST",
                url: "AJAX/TopicReply.ashx",
                data: { 'ID': ID, 'reply': text_reply },
                datatype: "text/json",
                beforeSend: function () {
                    $("#SendMessage").append('<span>发送中...</span><img src="../img/Common/loading.gif" alt="loading" />');
                },
                success: function (msg) {
                    alert("回复成功！");
                    location.reload();
                },
                complete: function (data) {
                    $("#SendMessage").empty();
                }
            });
        }
    </script>
</asp:Content>